package com.jxy.mail.web.api;

import com.jxy.BBM_info.BBM;
import com.jxy.BBM_info.BBM_table;
import com.jxy.mail.service.IMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * MailController
 *
 * @author Jxy
 * @date 2022/3/10
 * @Description 邮件
 */
@RestController
@RequestMapping("/api")
public class MailController {

    private final IMailService mail;

    @Autowired
    public MailController(IMailService mail) {
        this.mail = mail;
    }

    @PostMapping("/sendMail")
    public void sendMail(@RequestBody BBM bbm) {
        BBM_table firstTable = bbm.getFirstTable();
        String to = "jseryx@126.com";
        String subject = "测试";
        String content = "邮件内容";
        if (firstTable != null) {
            // TODO 后续完善，先检查是否包含列 在取值， 方法增加到bbm 结构中
            to = firstTable.getRowValue(0, "TO").toString();
            subject = firstTable.getRowValue(0, "SUBJECT").toString();
            content = firstTable.getRowValue(0, "CONTENT").toString();
        }

        mail.sendMail(to, subject, content);
    }

}
